GCC_BIN ?= $(shell which g++)
CARGO_BIN ?= $(shell which cargo)

gen:
	cbindgen --config cbindgen.toml -l c++ --crate blk1010_ffi --output csrc/blk1010_ffi.h
	cbindgen --config cbindgen_py.toml -l c --crate blk1010_ffi --output python/pffi.h

leak:
	leaks -atExit -- csrc/test

run: gen clean build
	./csrc/test

clean:
	$(CARGO_BIN) clean -p blk1010_ffi
	rm -f ./csrc/test

build:
	$(CARGO_BIN) build --release 
	$(GCC_BIN) -std=c++11 -Wall -o ./csrc/test ./csrc/test.cc -I . -L ./target/release -lblk1010_ffi
android:
	cp android-config.toml $(HOME)/.cargo/config
	cargo clean
	cargo build --target aarch64-linux-android --release --package blk1010_ffi
	cargo build --target armv7-linux-androideabi --release --package blk1010_ffi
	nm -D ../../target/aarch64-linux-android/release/libblk1010_ffi.so | grep Java_com_brix_ffi_Blk
	rm $(HOME)/.cargo/config

ios:
	cargo clean
	cargo lipo --release --package blk1010_ffi
mac:
	cargo clean
	cargo build --target aarch64-apple-darwin --release --package blk1010_ffi
